/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uvexposureapplication.rpc;

import java.util.HashMap;
import java.util.Map;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import uvexposureapplication.eventrouting.Consumer;
import uvexposureapplication.eventrouting.Producer;
import uvexposureapplication.eventrouting.elvin.ElvinConsumer;
import uvexposureapplication.eventrouting.elvin.ElvinProducer;
import uvexposureapplication.eventrouting.elvin.notificationlistener.ServerNotificationListener;

/**
 *
 * @author matthieukluj
 */
public abstract class AbstractPseudoRPCClientStub implements Observer, Runnable {

    public String serverName;
    public String methodName;
    public String parameters;
    public Producer producer;
    public Consumer consumer;
    public ServerNotificationListener ntf;

    public AbstractPseudoRPCClientStub(String methodName,
            String parameters, String server) {
        this.methodName = methodName;
        this.parameters = parameters;
        this.ntf = new ServerNotificationListener();
        this.ntf.addObserver(this);
        this.producer = new ElvinProducer(server);
        this.consumer = new ElvinConsumer(server, this.ntf);
    }

    public abstract void produce();

    public abstract void subscribeToServer();

    @Override
    public void run() {
        this.subscribeToServer();
        this.produce();
        this.close();
    }
    
    public void close() {
        this.consumer.closeConnection();
        this.producer.closeConnection();
    }
}
